<template>
  <div class="searchPage"  :class="{centerControl:modeControl}">
    <div class="imgbox" v-if="modeControl">
       <span class="biaoz">BaiDu</span>
    </div>
    <div class="searchInput">
      <div class="inputLeft">
          <multiselect
            v-model="value"
            tag-placeholder="创建新分类"
            placeholder="请输入或选择分类"
            label="name"
            track-by="code"
            :options="options"
            :multiple="true"
            :taggable="true"
            @tag="addTag"
        ></multiselect>
      </div>
      <div class="inputRight">
          <div class="btn">搜索</div>
      </div>
    </div>
  </div>
</template>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<style scoped>
.imgbox {
  height: 229px;
  text-align: center;
  font-size: 30px;
  color: white;
  position: relative;
}
.biaoz {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translate(-50%);
}
.searchPage {
  display: flex;
  flex-flow: column nowrap;
}
.centerControl {
  height: 370px;
  width: 642px;
  margin: auto;
}
.searchInput {
  height: 45px;
  margin: 5px 0;
  line-height: 45px;
  box-sizing: border-box;
  display: flex;
  position: relative;
}
.multiselect {
    line-height: 5px !important;
    height: 5px !important;
}
.inputLeft {
    flex-grow: 1;
}
.inputRight {
    width: 90px;
    position: relative;
}
.btn {
  background-color: #ccc;
  padding: .1rem 1rem;
  margin: 0 10px;
  height: 35px;
  line-height: 35px;
  position: absolute;
  top: 50%;
  transform: translate(0,-50%)
}
.imgbox {
}
</style>

<script>
import Multiselect from "vue-multiselect";
export default {
    components: {
      Multiselect
    },
    data() {
      return {
      // 选择分类
        value: [{ name: "文章", code: "js" }],
      // 下拉选项
        options: [
          { name: "文章", code: "sesice" },
          { name: "视频", code: "sad" },
          { name: "图片", code: "adadad" }
        ],
      };
    },
    props:{
        // 搜索模式控制
        modeControl: {
            // true为首页模式
            default:true,
            type:Boolean

        }
    },
    methods: {
      addTag(newTag) {
        const tag = {
          name: newTag,
          code: newTag.substring(0, 2) + Math.floor(Math.random() * 10000000)
        };
        this.options.push(tag);
        this.value.push(tag);
      }
    }
};
</script>